package com.Model.Date;

import java.util.*;
import java.text.*;

public class DateTime {
	private Date now;
	private Calendar calendar;
	private int year;
	private int month;
	private int day;
	private int hours;
	private int minutes;
	private int seconds;

	public DateTime(){
		calendar = Calendar.getInstance();
		now = new Date();
		calendar.setTime(now);					//放入Date类型数据
	}

	public Date getDate(){
		return now;
	}

	public void setDate(Date date){
		this.now = date;
	}

	public void setDate(int year, int month, int day, int hours, int minutes, int seconds){
		calendar.set(year,month,day,hours,minutes,seconds);
		now = calendar.getTime();
	}

	//settime的set和get方法
	public String getSettime() {
		String value = null;
		//将Date类型的时间转换成指定格式的字符串
		DateFormat d2 = DateFormat.getDateTimeInstance();
		value = d2.format(now);
		return value;
	}
	public Date setSettime(String settime) {
		//将字符串类型的日期转换成Date类型的指定格式的日期
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		ParsePosition pos = new ParsePosition(0);//从第一个字符开始解析
		this.now = f.parse(settime,pos);/*对参数msg_create_date（String类型）从第一个字
											符开始解析（由pos），转换成java.util.Date类型，
											而这个Date的格式为"yyyy-MM-dd"
											（因为SimpleDateFormat formatter =
											new SimpleDateFormat("yyyy-MM-dd");）*/
		return this.now;
	}

	public int getYear() {
		year = calendar.get(Calendar.YEAR);
		return year;
	}

	public void setYear(int year) {
		this.year = year;
		calendar.set(Calendar.YEAR, this.year);
		now = calendar.getTime();
	}

	public int getMonth() {
		month = calendar.get(Calendar.MONTH);
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
		calendar.set(Calendar.MONTH, month);
		now = calendar.getTime();
	}

	public int getDay() {
		day = calendar.get(Calendar.DATE);
		return day;
	}

	public void setDay(int day) {
		this.day = day;
		calendar.set(Calendar.DATE, day);
		now = calendar.getTime();
	}

	public int getHours() {
		return hours;
	}

	public void setHours(int hours) {
		this.hours = hours;
	}

	public int getMinutes() {
		return minutes;
	}

	public void setMinutes(int minutes) {
		this.minutes = minutes;
	}

	public int getSeconds() {
		return seconds;
	}

	public void setSeconds(int seconds) {
		this.seconds = seconds;
	}

	public boolean DateCompare(DateTime dateTime){
		boolean result;
		long t = now.getTime() - dateTime.getDate().getTime();
		result = t >= 0;
		return result;
	}
}
